<script language="javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js "></script>
<script language="javascript" src="http://api.weixinzjit.com/api/www/js/wx_jsapi_v_1.0.js"></script>
<script language="javascript">

var ShareTitle = '定制祝福，立邦为你刷新又一年';
var ShareDesc = "浓情岁末，定制语音祝福树传递感谢与思念，立邦与你一起刷又一年。";
var ShareUrl = 'http://api.weixinzjit.com/lb/index.php';
var ShareImg = 'http://api.weixinzjit.com/lb/img/share_ico.jpg';
var ShareUrl2 = 'http://api.weixinzjit.com/lb/share.php?';


var ISEND = true;

var ApiList = [
	//与分享有关的接口
	'onMenuShareTimeline',
	'onMenuShareAppMessage',
	//与声音有关的接口 
	'translateVoice', 'startRecord', 'stopRecord', 
	'onRecordEnd', 'playVoice', 'pauseVoice', 
	'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice'  ] ;

/**
 * 设置定制的分享信息
 */
function resetShare(){ 
	if( selectColor <1 ) return false;
	if( voice.localId.length < 1 ) return false;
	wx.uploadVoice({
		localId: voice.localId,
		success: function (res) { 
				voice.serverId = res.serverId;
				$('body').attr('username')
				ShareUrl = ShareUrl2 + 'vid='+res.serverId+'&index='+selectColor;
				ShareDesc = $('body').attr('d_username')+'为你定制了语音祝福树，感谢有你的陪伴，2016让我们一起刷新又一年。';
				ShareTitle = '快来倾听我为你定制的祝福树';
				doResetShare();
		}
	});
	 
}

/**
 * 设置默认的分享信息
 */
function doResetShare(){ 
	wx.onMenuShareAppMessage({
	      title: ShareTitle,
	      desc: ShareDesc,
	      link: ShareUrl,
	      imgUrl: ShareImg,
	      trigger: function (res) {  /*  alert('用户点击发送给朋友');   */ },
	      success: function (res) {  /* alert('已分享'); */ },
	      cancel: function (res) { /* alert('已取消'); */ },
	      fail: function (res) { /* alert(JSON.stringify(res)); */ }
	 }); 
	 
	 wx.onMenuShareTimeline({ // 2.2 监听"分享到朋友圈"按钮点击、自定义分享内容及分享结果接口
	      title: ShareDesc, 
	      link: ShareUrl, 
	      imgUrl: ShareImg,
	      trigger: function (res) {  /* alert('用户点击分享到朋友圈'); */  },
	      success: function (res) {  /* alert('已分享'); */ },
	      cancel: function (res) { /* alert('已取消'); */ },
	      fail: function (res) { /* alert(JSON.stringify(res)); */ }
	 }); 
}

var CallbackList = function(){ 
	doResetShare();
	wx.startRecord({
		  cancel: function () {
			alert('用户拒绝授权录音');
		  },
		  success: function (res) {  
		  		wx.stopRecord({  
					  success: function (res) { },
					  fail: function (res) { }
				}); 
		  }
	});
	$('.p2_huatong').bind('touchstart', function(ev){  
	  	ev.preventDefault();  
		$('.p2_bo').addClass('mv'); 
		wx.startRecord({
		  cancel: function () {
			alert('用户拒绝授权录音');
		  } 
		}); 
	}).bind('touchend',function(){
		wx.stopRecord({
		  success: function (res) {
			swiper.slideNext(); 
			voice.localId = res.localId;
		  },
		  fail: function (res) {
			alert('祝福还不够哦～还请多说几句吧！');
		  }
		}); 
	});
	
	$('.page3 .p3_btnbox .pbtn_1').bind('touchstart', function(ev){ 
	  	ev.preventDefault();
		if(!ISEND){ return false; }
		ISEND = false;
		if(voice.localId){ 
			wx.playVoice({
				  localId: voice.localId
			});
			playbo();
			wx.onVoicePlayEnd({
				complete: function (res) {
					if(!ISEND){
						stopbo();  
					}
					ISEND = true;
				}
			}); 
		}else{
			alert('请先使录制一段声音');
		}
	});
	
	$('.music').bind('touchstart',function(ev){
		ev.preventDefault();
		var music = document.getElementById('music');
		if($(this).hasClass('music_play')){
			$(this).removeClass('music_play').addClass('music_stop');
			music.pause();
		}else{
			$(this).removeClass('music_stop').addClass('music_play');
			music.play();
		}
	});
}

$(function(){
	ZJWX(ApiList,CallbackList,false);
});

</script>